import { _decorator, Component, game, Label, Node } from 'cc';
import { eventDispatcher } from './eventDispatcher';
import { gameState } from './gameState';
const { ccclass, property } = _decorator;

@ccclass('pageReviveAction')
export class pageReviveAction extends Component {
    @property(Label) free_times:Label = null;
    click_free(){
        if(gameState.ad_free_times>0){
            this.node.active = false;
            gameState.ad_free_times -= 1;
            eventDispatcher.get_target().emit(eventDispatcher.REMOVE_ACTION);
        }else{
            eventDispatcher.get_target().emit(eventDispatcher.TIPS_MSG,"free times is 0");
        }
    }
    click_thanks(){
        this.node.active = false;
        eventDispatcher.get_target().emit(eventDispatcher.OPEN_OVER);
    }
    open_page(){
        this.node.active = true;
        this.free_times.string = "("+gameState.ad_free_times+"/1)";
    }
    start() {
        this.node.active = false;
        eventDispatcher.get_target().on(eventDispatcher.OPEN_REVIVE,this.open_page,this);
    }
    update(deltaTime: number) {   }
}


